﻿using System;
using YIUIBind;
using YIUIFramework;
using UnityEngine;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using DG.Tweening;

namespace YIUI.Loading
{
    /// <summary>
    /// Author  YIUI
    /// Date    2025.8.31
    /// </summary>
    public sealed partial class LoadingPanel:LoadingPanelBase,IYIUIOpen<string,Action<float>>
    {
    
        #region 生命周期
        
        protected override void Initialize()
        {
            Debug.Log($"LoadingPanel Initialize");
        }

        protected override void Start()
        {
            Debug.Log($"LoadingPanel Start");
        }

        protected override void OnEnable()
        {
            Debug.Log($"LoadingPanel OnEnable");
        }

        protected override void OnDisable()
        {
            Debug.Log($"LoadingPanel OnDisable");
        }

        protected override void OnDestroy()
        {
            Debug.Log($"LoadingPanel OnDestroy");
        }

        protected override async UniTask<bool> OnOpen()
        {
            await UniTask.CompletedTask;
            Debug.Log($"LoadingPanel OnOpen");
            return true;
        }

        protected override async UniTask<bool> OnOpen(ParamVo param)
        {
            return await base.OnOpen(param);
        }

        private string m_OpenString;
        private Action<float> m_ProgressAction;
        
        public async UniTask<bool> OnOpen(string p1, Action<float> p2)
        {
            m_OpenString = p1;
            m_ProgressAction = p2;

            await UniTask.CompletedTask;

            SimulationLoading().Forget();
            
            return true;
        }

        private async UniTask<bool> SimulationLoading()
        {
            u_DataProgress.SetValue(0);
            await DOTween.To(() => u_DataProgress.GetValue(),x=>
            {
                u_DataProgress.SetValue(x);
                m_ProgressAction?.Invoke(x);
            },100,2);
            
            return true;
        }
        
        #endregion

        #region Event开始


        #endregion Event结束


    }
}